web/src/pages/[...section].astro
306 lines · 8009 bytes
1---
2
3
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 alternativeTo?: string[];
21 categoryName: string,
22 otherSections: Section[],
23}
24
25const {
26 title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
27 alternativeTo, categoryName, intro,
28} = Astro.props;
29
30/**
31 * Make a list of keywords, for the <meta keywords> tag
32 */
33const makeKeyWordTag = () => {
34 const keywords = [];
35 keywords.push(`free and open source ${title} software`);
36 keywords.push(`private ${title} comparison`);
37 (alternativeTo || []).forEach((alt: string) => {
38 keywords.push(`privacy-respecting ${alt} alternative`);
39 keywords.push(`free open source ${alt} alternative`);
40 });
41 (services || []).forEach((serv: Service) => {
42 keywords.push(serv.name);
43 });
44 keywords.push('ad free');
45 keywords.push('open source software');
46 keywords.push('privacy respecting apps');
47 return keywords.join(', ');
48};
49
50/**
51 * Make a page title
52 */
53const makePageTitle = () => {
54 return `${title} | Awesome Privacy`;
55};
56
57/**
58 * Make a string page intro, for the description tag
59 */
60const makeDescriptionTag = () => {
61 let description = `Privacy respecting ${title}. `;
62 if (services && services.length > 0) {
63 const serviceList = services.map((serv: Service) => serv.name);
64 description += `Compare ${serviceList.join(' vs ')} and more private, open source apps and services now. `
65 } else {
66 description += `Find private apps and services. This section is still a work in progress. `;
67 }
68 if (alternativeTo && alternativeTo.length > 0) {
69 description += `The best secure encrypted alternatives to ${alternativeTo.join(', ')} in 2024. `;
70 }
71 description += 'All this, and many more free and awesome tools and software.'
72 return description;
73};
74
75export async function getStaticPaths() {
76 const pages = await fetchData().then((data) => {
77 const results: Array<Props> = [];
78 if (!data || !data.categories) return results;
79 (data as AwesomePrivacy).categories.forEach((category) => {
80 const sections = category.sections.map((section) => ({
81 slug: `${slugify(category.name)}/${slugify(section.name)}`,
82 title: section.name,
83 services: section.services,
84 intro: section.intro,
85 notableMentions: section.notableMentions,
86 furtherInfo: section.furtherInfo,
87 wordOfWarning: section.wordOfWarning,
88 alternativeTo: section.alternativeTo,
89 categoryName: category.name,
90 otherSections: category.sections,
91 }));
92 results.push(...sections);
93 });
94 return results;
95 });
96
97 return pages.map((props: Props) => {
98 return {params: { section: props.slug }, props };
99 });
100}
101
102const makePaginationLinks = () => {
103 const index = otherSections.findIndex(section => section.name === title);
104 const previousSection = index > 0 ? otherSections[index - 1].name : null;
105 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
106 return { previous: previousSection, next: nextSection };
107};
108
109const { previous, next } = makePaginationLinks();
110
111---
112
113<Layout title={makePageTitle()} keywords={makeKeyWordTag()} description={makeDescriptionTag()} >
114 <Main>
115
116 <h2>{title}</h2>
117
118 {intro && (
119 <section class="intro">
120 <p set:html={parseMarkdown(intro)}></p>
121 </section>
122 )}
123
124 <ServiceList services={services} sectionName={title} categoryName={categoryName} />
125
126 <details class="about-this-page">
127 <summary>Objective of this page</summary>
128 <p>
129 Find the best free, open source, E2E encrypted and private alternative to
130 {(alternativeTo || []).map((alt) => (<span>{alt}, </span>))} now.
131 </p>
132 <p>
133 Compare {(services || []).map((serv) => (<span>{serv.name} vs </span>))}
134 </p>
135 <p>
136 Discover the best {title} tools for Android, iPhone, Linux, PC and Chrome to download now.
137 And choose secure, self-hosted, peer-to-peer and independant alternatives in 2024
138 </p>
139 <p>
140 <b>Stop the invasion of privacy from big tech, improve data security stay safe.</b>
141 </p>
142 </details>
143
144
145 {notableMentions && (
146 <section class="notable-mentions">
147 <h3>Notable Mentions</h3>
148 { Array.isArray(notableMentions) ?
149 <ul>
150 {notableMentions.map((mention) => (
151 <li>
152 <a href={mention.url}>{mention.name}</a>
153 {mention.description && (
154 <span>- </span>
155 <span set:html={parseMarkdown(mention.description)}></span>
156 )}
157 </li>
158 ))}
159 </ul> :
160 <p set:html={parseMarkdown(notableMentions)}></p>
161 }
162 </section>
163 )}
164
165 {furtherInfo && (
166 <section class="further-info">
167 <h3>Notes</h3>
168 <p set:html={parseMarkdown(furtherInfo)}></p>
169 </section>
170 )}
171
172 {wordOfWarning && (
173 <section class="word-of-warning">
174 <h3>Word of Warning</h3>
175 <p set:html={parseMarkdown(wordOfWarning)}></p>
176 </section>
177 )}
178
179 <div class="pagination-navigation">
180 { previous ? (
181 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
182 <span>← Previous</span>
183 <p>{previous}</p>
184 </Button>
185 ) : <p class="nothing"></p>}
186 <a href={`/${slugify(categoryName)}`} class="go-to-category">
187 View all in {categoryName} ({otherSections.length})
188 </a>
189 { next && (
190 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
191 <span>Next →</span>
192 <p>{next}</p>
193 </Button>
194 )}
195 </div>
196 </Main>
197</Layout>
198
199<style lang="scss">
200
201section {
202 padding-bottom: 1rem;
203 &:not(:last-child) {
204 border-bottom: 2px solid var(--accent-3);
205 }
206}
207
208h2 {
209 font-size: 2rem;
210 margin: -2rem 0 2rem -2rem;
211 box-shadow: 6px 6px 0 var(--foreground);
212 background: var(--accent);
213 color: var(--accent-fg);
214 width: fit-content;
215 padding: 0.25rem 0.5rem;
216 }
217
218.pagination-navigation {
219 display: flex;
220 justify-content: space-between;
221 align-items: center;
222 padding: 1rem 0;
223 :global(.button) {
224 min-width: 120px;
225 width: fit-content;
226 padding: 0.25rem 1rem;
227 text-align: right;
228 &:first-child { text-align: left; }
229 p {
230 margin: 0;
231 font-weight: normal;
232 font-size: 1rem;
233 }
234 span {
235 font-size: 0.8rem;
236 }
237
238 }
239 .nothing {
240 width: 120px;
241 }
242 .go-to-category {
243 color: var(--foreground);
244 font-size: 0.8rem;
245 opacity: 0.5;
246 @media (max-width: 768px) {
247 display: none;
248 }
249 }
250}
251
252.intro {
253 font-style: italic;
254 opacity: 0.7;
255}
256
257
258.further-info, .notable-mentions, .word-of-warning {
259 h3 {
260 font-size: 1.4rem;
261 margin: 1rem 0;
262 }
263 :global(p) {
264 font-size: 0.9rem;
265 opacity: 0.7;
266 :global(strong) {
267 font-weight: 500;
268 }
269 :global(a) {
270 color: var(--foreground);
271 transition: all 0.15s ease-in-out;
272 &:hover {
273 color: var(--accent);
274 }
275 }
276 }
277 :global(strong) {
278 font-weight: 500;
279 }
280 :global(h4) {
281 font-size: 1.2rem;
282 margin: 0.5rem 0 0 0;
283 }
284 :global(ul) {
285 list-style: circle;
286 padding-left: 1rem;
287 font-size: 0.9rem;
288 opacity: 0.7;
289 li {
290 margin-bottom: 0.25rem;
291 :global(p) {
292 display: inline;
293 }
294 }
295 }
296}
297.about-this-page {
298 summary {
299 display: none;
300 }
301 font-size: 0.9rem;
302 opacity: 0.7;
303}
304
305
306</style>